package cn.wolfcode.trip.core.service.impl;

import cn.wolfcode.trip.core.domain.Region;
import cn.wolfcode.trip.core.mapper.RegionMapper;
import cn.wolfcode.trip.core.query.RegionQueryObject;
import cn.wolfcode.trip.core.service.IRegionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class RegionServiceImpl implements IRegionService {

    @Autowired
    private RegionMapper regionMapper;

    public List<Region> queryByParent(Long parentId) {

        return regionMapper.selectByParent(parentId);
    }

    public void saveOrUpdate(Region region) {
        if(region.getId()==null){
            regionMapper.insert(region);
        }else {
            regionMapper.updateByPrimaryKey(region);
        }
    }

    public void updateState(Long id, Integer state) {

        regionMapper.updateState(id,state);
    }

    public List<Region> listAll(RegionQueryObject qo) {
        return regionMapper.selectAll(qo);
    }
}
